package com.hua.yuan.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hua.yuan.R;
import com.hua.yuan.ui.module.MyBuyBean;

import java.util.List;

/**
 * Created by huangyang on 2018/6/23.
 * 我的购买记录
 */

public class MyBuyAdapter extends BaseAdapter {

    private Context context;

    private List<MyBuyBean> list;

    public MyBuyAdapter(Context context) {
        this.context = context;
    }

    public List<MyBuyBean> getList() {
        return list;
    }

    public void setList(List<MyBuyBean> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        return list == null ? null : list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return list == null ? 0 : i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {

            view = LayoutInflater.from(context).inflate(R.layout.buy_item_view, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) view.getTag();

        }

        viewHolder.bind(i);

        return view;
    }

    class ViewHolder {

        private ImageView buyImg;
        private TextView buyName;
        private TextView buyType;
        private TextView buyPlayTime;
        private TextView buyMoney;
        private TextView buyTime;

        ViewHolder(View view) {
            buyImg = view.findViewById(R.id.buyImg);
            buyName = view.findViewById(R.id.buyName);
            buyType = view.findViewById(R.id.buyType);
            buyPlayTime = view.findViewById(R.id.buyPlayTime);
            buyMoney = view.findViewById(R.id.buyMoney);
            buyTime = view.findViewById(R.id.buyTime);

        }

        void bind(int i) {

            MyBuyBean bean = list.get(i);
            Glide.with(context).load(bean.getImageUrl()).into(buyImg);
            buyName.setText(bean.getName());
            buyType.setText(bean.getType());
            buyPlayTime.setText(bean.getPlayTime());
            buyMoney.setText(bean.getMoney());
            buyTime.setText(bean.getBuyTime());

        }

    }

}
